package org.finesys.common.security.authorization;

import org.finesys.common.security.authentication.gitee.OAuth2GiteeAuthenticationProvider;
import org.finesys.common.security.authentication.password.DaoAuthenticationProvider;
import org.finesys.common.security.authentication.password.OAuth2ResourceOwnerPasswordAuthenticationProvider;
import org.finesys.common.security.authentication.sms.OAuth2ResourceOwnerSmsAuthenticationProvider;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;

import java.util.Arrays;
import java.util.List;

public class AuthenticationProvidersCustomCustomizer implements Customizer<HttpSecurity> {


    @Override
    public void customize(HttpSecurity httpSecurity) {
        List<AuthenticationProvider> providerList = Arrays.asList(
                //支持OAuth2ResourceOwnerPasswordAuthenticationToken类型的认证
                new OAuth2ResourceOwnerPasswordAuthenticationProvider(httpSecurity),
                //支持OAuth2ResourceOwnerSmsAuthenticationToken类型的认证
                new OAuth2ResourceOwnerSmsAuthenticationProvider(httpSecurity),
                //自定义的gitee oauth2登录
                new OAuth2GiteeAuthenticationProvider(httpSecurity),
                //支持UsernamePasswordAuthenticationToken类型的认证
                new DaoAuthenticationProvider()
        );
        providerList.forEach(httpSecurity::authenticationProvider);
    }
}
